package cn.edu.scnu.show_and_find_movies.controller;

import cn.edu.scnu.entry.model.Result;
import cn.edu.scnu.show_and_find_movies.model.Movie;
import cn.edu.scnu.show_and_find_movies.service.ShowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ShowController {
    @Autowired
    private ShowService showService;
    @GetMapping("/api/movie/hot")
    Result getHotMovies(){
        return Result.success("成功获取热门影片列表（热播排行）",showService.getHotMovies());
    }
    @GetMapping("/api/movie/searchByType")
    Result getMoviesByType(String type){
        List<Movie> movies = showService.getMoviesByType(type);
        if(movies.isEmpty())
            return Result.error(404,type+"类型影片未找到");
        return Result.success("成功获取"+type+"类型的影片",movies);
    }
    @GetMapping("/api/movie/searchByRegion")
    Result getMoviesByRegion(String region){
        List<Movie> movies = showService.getMoviesByRegion(region);
        if(movies.isEmpty())
            return Result.error(404,region+"地区的影片未找到");
        return Result.success("成功获取"+region+"地区的影片",movies);
    }
    @GetMapping("/api/movie/detail/{movieId}")
    Result getMovieByDetail(@PathVariable Integer movieId){
        Movie movie = showService.getMovieById(movieId);
        if(movie==null)
            return Result.error(404,"id为"+movieId+"的影片未找到");
        return Result.success("成功获取影片详情",movie);
    }
    @GetMapping("/api/movie/play/{movie_id}")
    Result playMovie(@PathVariable Integer movie_id){
        Movie movie = showService.getMovieById(movie_id);
        if(movie==null)
            return Result.error(404,"id为"+movie_id+"的影片未找到");
        return Result.success("成功获取影片播放地址",movie);
    }
}
